app.controller('updateCommodityContorller', ['$scope', 'ajax','$stateParams','$state', function ($scope, ajax,$stateParams,$state) {

    //添加分类
    ajax.get({
        url: 'back/commodity/query',
        data: {
            commodityId: $stateParams.commodityUpdateID
        },
        debug: false
    }).then(function (data) {
        $scope.customer = data;
    })

    ajax.get({
        url: 'back/commodityCategory/list',
        data:{
            level:1
        },
        debug: false
    }).then(function (data) {
        $scope.f_class=data;
        $scope.$watch('f.name', function(data) {
            if($scope.f){
                ajax.get({
                    url: 'back/commodityCategory/list',
                    data:{
                        parentId:$scope.f.name.categoryId
                    },
                    debug: false
                }).then(function (data) {
                    $scope.s_class=data;
                })
            }
        });
    })

    //修改商品
    $scope.commodityDetai = function(detail){
        ajax.post({
            url: 'back/commodity/update',
            data: detail,
            debug: true
        }).then(function (result) {
            Flash.create('success','修改成功', 'custom-class');
            $state.go('admin.commodity')
        })
    }
}]);